﻿using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Dapper;

namespace DapperExtensions
{
    public static partial class SqlMapperExtensions
    {
        public static readonly ICollection<IDapperInterceptor> Interceptors = new List<IDapperInterceptor>();

        private static CommandDefinition Clone(this CommandDefinition command, string sql, object param = null)
        {
            return new CommandDefinition(sql,
                param,
                command.Transaction,
                command.CommandTimeout,
                command.CommandType,
                command.Flags,
                command.CancellationToken);
        }

        private static void OnExecuting(DapperContext context)
        {
            foreach (var interceptor in Interceptors)
            {
                interceptor.OnExecuting(context);
            }
        }
    }
}